#!/bin/bash

# 输出时间和数据
function normalSend() {
    usage=$(cat /sys/fs/cgroup/memory/memory.usage_in_bytes)
    fdNum=$(ls /proc/1/fd|wc -l)
    threadNum=$(ls /proc/1/task|wc -l)
    normal_data="$current_time,$usage,$fdNum,$threadNum"
    url_normal_data="http://test-arch-test01-java02-ws8-rpc001.zhrpc.net/mem/normal/add/json?serviceName=$1&podName=$2&metricTime=$3"
    curl -X POST $url_normal_data -H 'Content-Type: application/json' -d "{\"content\":\"$normal_data\"}" &
}


# memory.stat
function memStatSend() {
    mem_stat=$(cat /sys/fs/cgroup/memory/memory.stat)
    data_1=$(echo "$mem_stat" | tr '\n' '@')
    url_mem_stat="http://test-arch-test01-java02-ws8-rpc001.zhrpc.net/mem/stat/add/json?serviceName=$1&podName=$2&metricTime=$3"
    curl -X POST $url_mem_stat -H 'Content-Type: application/json' -d "{\"content\":\"$data_1\"}"
}



# 获取当前时间并格式化
current_time=$(date +"%Y-%m-%dT%H:%M:%S")
host=$(hostname)
svcName=$(echo $host | sed 's/-[^-]*-[^-]*$//')


memStatSend $svcName $host $current_time &
normalSend $svcName $host $current_time
